home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / TCP.H < prev    next >
Text File  |  1993-08-09  |  9KB  |  287 lines

  1. #ifndef    _TCP_H
  2. #define    _TCP_H
  3.  
  4. /* TCP implementation. Follows RFC 793 as closely as possible */
  5. #ifndef    _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.  
  9. #ifndef    _MBUF_H
  10. #include "mbuf.h"
  11. #endif
  12.  
  13. #ifndef    _IFACE_H
  14. #include "iface.h"
  15. #endif
  16.  
  17. #ifndef    _INTERNET_H
  18. #include "internet.h"
  19. #endif
  20.  
  21. #ifndef _IP_H
  22. #include "ip.h"
  23. #endif
  24.  
  25. #ifndef    _NETUSER_H
  26. #include "netuser.h"
  27. #endif
  28.  
  29. #ifndef    _TIMER_H
  30. #include "timer.h"
  31. #endif
  32.  
  33. #define    DEF_WND        2048    /* Default receiver window */
  34. #define    RTTCACHE    16        /* # of TCP round-trip-time cache entries */
  35. #define    DEF_MSS        512        /* Default maximum segment size */
  36. #define    DEF_RTT        5000    /* Initial guess at round trip time (5 sec) */
  37. #define    MSL2        30        /* Guess at two maximum-segment lifetimes */
  38. #define    TCP_MAXOPT    40        /* Largest option field, bytes */
  39.  
  40. #define    geniss()    ((int32)msclock() << 12) /* Increment clock at 4 MB/sec */
  41.  
  42. /* Number of consecutive duplicate acks to trigger fast recovery */
  43. #define    TCPDUPACKS    3
  44.  
  45. /* Round trip timing parameters */
  46. #define    AGAIN        8        /* Average RTT gain = 1/8 */
  47. #define    LAGAIN        3        /* Log2(AGAIN) */
  48. #define    DGAIN        4        /* Mean deviation gain = 1/4 */
  49. #define    LDGAIN        2        /* log2(DGAIN) */
  50.  
  51. /* TCP segment header -- internal representation
  52.  * Note that this structure is NOT the actual header as it appears on the
  53.  * network (in particular, the offset and checksum fields are missing).
  54.  * All that knowledge is in the functions ntohtcp() and htontcp() in tcpsubr.c
  55.  */
  56. struct tcp {
  57.     int16 source;            /* Source port */
  58.     int16 dest;                /* Destination port */
  59.     int32 seq;                /* Sequence number */
  60.     int32 ack;                /* Acknowledgment number */
  61.     struct {
  62.         char congest;
  63.         char urg;
  64.         char ack;
  65.         char psh;
  66.         char rst;
  67.         char syn;
  68.         char fin;
  69.     } flags;
  70.     int16 wnd;                /* Receiver flow control window */
  71.     int16 checksum;
  72.     int16 up;                /* Urgent pointer */
  73.     int16 mss;                /* Optional max seg size */
  74.     char options[TCP_MAXOPT];
  75.     int optlen;
  76. };
  77. /* TCP options */
  78. #define    EOL_KIND    0
  79. #define    NOOP_KIND    1
  80. #define    MSS_KIND    2
  81.  
  82. #define    TCPLEN        20
  83. #define    MSS_LENGTH    4
  84. /* Resequencing queue entry */
  85. struct reseq {
  86.     struct reseq *next;        /* Linked-list pointer */
  87.     struct tcp seg;            /* TCP header */
  88.     struct mbuf *bp;        /* data */
  89.     int16 length;            /* data length */
  90.     char tos;                /* Type of service */
  91. };
  92. #define    NULLRESEQ (struct reseq *)0
  93.  
  94. /* TCP connection control block */
  95. struct tcb {
  96.     struct tcb *next;
  97.  
  98.     struct connection conn;
  99.  
  100.     char state;    /* Connection state */
  101.  
  102. /* These numbers match those defined in the MIB for TCP connection state */
  103. #define    TCP_CLOSED            1
  104. #define    TCP_LISTEN            2
  105. #define    TCP_SYN_SENT        3
  106. #define    TCP_SYN_RECEIVED    4
  107. #define    TCP_ESTABLISHED        5
  108. #define    TCP_FINWAIT1        6
  109. #define    TCP_FINWAIT2        7
  110. #define    TCP_CLOSE_WAIT        8
  111. #define    TCP_LAST_ACK        9
  112. #define    TCP_CLOSING            10
  113. #define    TCP_TIME_WAIT        11
  114.  
  115.     char reason;            /* Reason for closing */
  116. #define    NORMAL        0        /* Normal close */
  117. #define    RESET        1        /* Reset by other end */
  118. #define    TIMEOUT        2        /* Excessive retransmissions */
  119. #define    NETWORK        3        /* Network problem (ICMP message) */
  120.  
  121. /* If reason == NETWORK, the ICMP type and code values are stored here */
  122.     char type;
  123.     char code;
  124.  
  125.     /* Send sequence variables */
  126.     struct {
  127.         int32 una;            /* First unacknowledged sequence number */
  128.         int32 nxt;            /* Next sequence num to be sent for the first time */
  129.         int32 ptr;            /* Working transmission pointer */
  130.         int32 wl1;            /* Sequence number used for last window update */
  131.         int32 wl2;            /* Ack number used for last window update */
  132.         int16 wnd;            /* Other end's offered receive window */
  133.         int16 up;            /* Send urgent pointer */
  134.     } snd;
  135.     int32 iss;                /* Initial send sequence number */
  136.     int32 resent;            /* Count of bytes retransmitted */
  137.     int16 cwind;            /* Congestion window */
  138.     int16 ssthresh;            /* Slow-start threshold */
  139.     int dupacks;
  140.  
  141.     /* Receive sequence variables */
  142.     struct {
  143.         int32 nxt;            /* Incoming sequence number expected next */
  144.         int16 wnd;            /* Our offered receive window */
  145.         int16 up;            /* Receive urgent pointer */
  146.     } rcv;
  147.     int32 irs;                /* Initial receive sequence number */
  148.     int32 rerecv;            /* Count of duplicate bytes received */
  149.     int16 mss;                /* Maximum segment size */
  150.  
  151.     int16 window;            /* Receiver window and send queue limit */
  152.  
  153.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt));
  154.         /* Call when "significant" amount of data arrives */
  155.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt));
  156.         /* Call when ok to send more data */
  157.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new));
  158.         /* Call when connection state changes */
  159.     struct {                /* Control flags */
  160.         char force;            /* We owe the other end an ACK or window update */
  161.         char clone;            /* Server-type TCB, cloned on incoming SYN */
  162.         char retran;        /* A retransmission has occurred */
  163.         char active;        /* TCB created with an active open */
  164.         char synack;        /* Our SYN has been acked */
  165.         char rtt_run;        /* We're timing a segment */
  166.         char congest;
  167.     } flags;
  168.     char tos;                /* Type of service (for IP) */
  169.     int backoff;            /* Backoff interval */
  170.  
  171.     struct mbuf *rcvq;        /* Receive queue */
  172.     struct mbuf *sndq;        /* Send queue */
  173.     int16 rcvcnt;            /* Count of items on rcvq */
  174.     int16 sndcnt;            /* Number of unacknowledged sequence numbers on
  175.                              * sndq. NB: includes SYN and FIN, which don't
  176.                              * actually appear on sndq!
  177.                              */
  178.  
  179.     struct reseq *reseq;    /* Out-of-order segment queue */
  180.     struct timer timer;        /* Retransmission timer */
  181.     int32 rtt_time;            /* Stored clock values for RTT */
  182.     int32 rttseq;            /* Sequence number being timed */
  183.     int32 srtt;                /* Smoothed round trip time, milliseconds */
  184.     int32 mdev;                /* Mean deviation, milliseconds */
  185.     int32 lastactive;
  186.     int user;                /* User parameter (e.g., for mapping to an
  187.                              * application control block
  188.                              */
  189. };
  190. #define    NULLTCB    (struct tcb *)0
  191. /* TCP round-trip time cache */
  192. struct tcp_rtt {
  193.     int32 addr;                /* Destination IP address */
  194.     int32 srtt;                /* Most recent SRTT */
  195.     int32 mdev;                /* Most recent mean deviation */
  196. };
  197. #define    NULLRTT    (struct tcp_rtt *)0
  198. extern struct tcp_rtt Tcp_rtt[];
  199.  
  200. /* TCP statistics counters */
  201. struct tcp_stat {
  202.     int16 runt;                /* Smaller than minimum size */
  203.     int16 checksum;            /* TCP header checksum errors */
  204.     int16 conout;            /* Outgoing connection attempts */
  205.     int16 conin;            /* Incoming connection attempts */
  206.     int16 resets;            /* Resets generated */
  207.     int16 bdcsts;            /* Bogus broadcast packets */
  208. };
  209. extern struct mib_entry Tcp_mib[];
  210. #define    tcpRtoAlgorithm    Tcp_mib[1].value.integer
  211. #define    tcpRtoMin    Tcp_mib[2].value.integer
  212. #define    tcpRtoMax    Tcp_mib[3].value.integer
  213. #define    tcpMaxConn    Tcp_mib[4].value.integer
  214. #define    tcpActiveOpens    Tcp_mib[5].value.integer
  215. #define tcpPassiveOpens    Tcp_mib[6].value.integer
  216. #define    tcpAttemptFails    Tcp_mib[7].value.integer
  217. #define    tcpEstabResets    Tcp_mib[8].value.integer
  218. #define    tcpCurrEstab    Tcp_mib[9].value.integer
  219. #define    tcpInSegs    Tcp_mib[10].value.integer
  220. #define    tcpOutSegs    Tcp_mib[11].value.integer
  221. #define    tcpRetransSegs    Tcp_mib[12].value.integer
  222. #define    tcpInErrs    Tcp_mib[14].value.integer
  223. #define    tcpOutRsts    Tcp_mib[15].value.integer
  224. #define    NUMTCPMIB    15
  225.  
  226. extern struct tcb *Tcbs;
  227.  
  228. extern int Tcp_retry, Tcp_trace, Tcp_syndata;
  229. extern int16 Tcp_mss, Tcp_window;
  230. extern int32 Tcp_irtt;
  231. extern char *Tcpstates[], *Tcpreasons[];
  232.  
  233. /* In tcpcmd.c: */
  234. void st_tcp __ARGS((struct tcb *tcb));
  235.  
  236. /* In tcphdr.c: */
  237. struct mbuf *htontcp __ARGS((struct tcp *tcph,struct mbuf *data,
  238.     struct pseudo_header *ph));
  239. int ntohtcp __ARGS((struct tcp *tcph,struct mbuf **bpp));
  240.  
  241. /* In tcpin.c: */
  242. void reset __ARGS((struct ip *ip,struct tcp *seg));
  243. void send_syn __ARGS((struct tcb *tcb));
  244. void tcp_input __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  245.     int rxbroadcast));
  246. void tcp_icmp __ARGS((int32 icsource,int32 source,int32 dest,
  247.     char type,char code,struct mbuf **bpp));
  248.  
  249. /* In tcpsubr.c: */
  250. void close_self __ARGS((struct tcb *tcb,int reason));
  251. struct tcb *create_tcb __ARGS((struct connection *conn));
  252. struct tcb *lookup_tcb __ARGS((struct connection *conn));
  253. void rtt_add __ARGS((int32 addr,int32 rtt));
  254. struct tcp_rtt *rtt_get __ARGS((int32 addr));
  255. int seq_ge __ARGS((int32 x,int32 y));
  256. int seq_gt __ARGS((int32 x,int32 y));
  257. int seq_le __ARGS((int32 x,int32 y));
  258. int seq_lt __ARGS((int32 x,int32 y));
  259. int seq_within __ARGS((int32 x,int32 low,int32 high));
  260. void setstate __ARGS((struct tcb *tcb,int newstate));
  261.  
  262. /* In tcpout.c: */
  263. void tcp_output __ARGS((struct tcb *tcb));
  264.  
  265. /* In tcptimer.c: */
  266. int32 backoff __ARGS((int n));
  267. void tcp_timeout __ARGS((void *p));
  268.  
  269. /* In tcpuser.c: */
  270. int close_tcp __ARGS((struct tcb *tcb));
  271. int del_tcp __ARGS((struct tcb *tcb));
  272. int kick __ARGS((int32 addr));
  273. int kick_tcp __ARGS((struct tcb *tcb));
  274. struct tcb *open_tcp __ARGS((struct socket *lsocket,struct socket *fsocket,
  275.     int mode,int16 window,
  276.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt)),
  277.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt)),
  278.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new)),
  279.     int tos,int user));
  280. int recv_tcp __ARGS((struct tcb *tcb,struct mbuf **bpp,int16 cnt));
  281. void reset_all __ARGS((void));
  282. void reset_tcp __ARGS((struct tcb *tcb));
  283. int send_tcp __ARGS((struct tcb *tcb,struct mbuf *bp));
  284. int tcpval __ARGS((struct tcb *tcb));
  285.  
  286. #endif    /* _TCP_H */
  287.